package com.app.teaware.statis;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.app.teaware.R;
import com.app.teaware.basis.BasisActivity;
import com.app.teaware.basis.MyViewPagerAdapter;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;

import java.util.ArrayList;

import butterknife.BindView;

public class StatisTabActivity extends BasisActivity {


    @BindView(R.id.tablayout)
    CommonTabLayout tablayout;
    @BindView(R.id.viewpager)
    ViewPager viewPager;
    MyViewPagerAdapter myViewPagerAdapter;

    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();

    @Override
    public void initViews() {
        super.initViews();
        setContentView(R.layout.base_tab_activity);
        setTitle("统计分析");
        setTitleLeftButton(null);
    }


    @Override
    public void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        setView();
    }

    private void setView() {

        Fragment[] fms = new Fragment[2];
        fms[0] = FireAlarmStatisFragment.newInstance();
        fms[1] = FireRiskStatisFragment.newInstance();


        myViewPagerAdapter = new MyViewPagerAdapter(getSupportFragmentManager(), fms);
        viewPager.setAdapter(myViewPagerAdapter);
        viewPager.setOffscreenPageLimit(3);


        mTabEntities =  new ArrayList<>();
        mTabEntities.add(new TabEntity("警情统计", 0, 0));
        mTabEntities.add(new TabEntity("防火监督数据分析", 0, 0));
        tablayout.setTabData(mTabEntities);
        tablayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                viewPager.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {
            }
        });
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                tablayout.setCurrentTab(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        viewPager.setCurrentItem(0);
    }
    public class TabEntity implements CustomTabEntity {
        public String title;
        public int selectedIcon;
        public int unSelectedIcon;

        public TabEntity(String title, int selectedIcon, int unSelectedIcon) {
            this.title = title;
            this.selectedIcon = selectedIcon;
            this.unSelectedIcon = unSelectedIcon;
        }

        @Override
        public String getTabTitle() {
            return title;
        }

        @Override
        public int getTabSelectedIcon() {
            return selectedIcon;
        }

        @Override
        public int getTabUnselectedIcon() {
            return unSelectedIcon;
        }
    }


}
